package com.yunmang.utils;

import android.content.Context;
import android.os.Bundle;

import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SynthesizerListener;

/**
 * 封装语音工具类
 * @author ltt
 *
 */
public class SpeakUtils {
	private SpeechSynthesizer mTts;
	private Context context;
	public SpeakUtils(Context context){
		this.context=context;
		mTts=SpeechSynthesizer.createSynthesizer(context, null); 
	}
	public boolean isSpeeach(){
		return mTts.isSpeaking();
	}
	public void stopSppach(){
		if(isSpeeach()){
			mTts.stopSpeaking();
		}
	}
	public void initParams(String str){
		mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan");// 设置发音人
		mTts.setParameter(SpeechConstant.SPEED, "60");// 设置语速
		mTts.setParameter(SpeechConstant.VOLUME, "100");// 设置音量，范围0~100
		mTts.setParameter(SpeechConstant.ENGINE_TYPE,SpeechConstant.TYPE_CLOUD); // 设置云端
		//3.开始合成  
		mTts.startSpeaking(str, mSynListener);    
	}
	//合成监听器  
	private SynthesizerListener mSynListener = new SynthesizerListener(){

		@Override
		public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) {
			
		}

		@Override
		public void onCompleted(SpeechError arg0) {
			
		}

		@Override
		public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) {
			
		}

		@Override
		public void onSpeakBegin() {
			
		}

		@Override
		public void onSpeakPaused() {
			
		}

		@Override
		public void onSpeakProgress(int arg0, int arg1, int arg2) {
			
		}

		@Override
		public void onSpeakResumed() {
			
		}};
}